package demo_02;

/**
 * description: TestPolym <br>
 * date: 2022/1/31 1:41 上午 <br>
 * author: shesaifei <br>
 * version: 1.0 <br>
 */
public class TestPolym {
    public static void main(String[] args) {
        Animal animal = new Animal();
        animalCry(animal);

        Dog dog = new Dog();
        dog.shout();
        dog.age = 1;
        System.out.println(dog.age);

        Cat cat = new Cat();
        String eat = cat.eat();
        System.out.println(eat);
        animalCry(cat);
    }

    static void animalCry(Animal a) {
        a.shout();

    }
}

class Animal {
    String name;
    int age;

    public void song() {
        System.out.println("情歌！");
    }

    public void shout() {
        System.out.println("叫了一声");
    }
}

class Dog extends Animal {
    public void shout() {
        System.out.println("汪汪叫");
    }
}

class Cat extends Animal {
    public String eat() {
        return "爱吃鱼";
    }

    public void shout() {
        System.out.println("喵喵");
    }
}